#!/usr/bin/python
import os, sys, zestlib as zest
################################################################################
################################################################################
# 1. build a list of source directoriers (srcdirs)
# 2. visit each srcdir and run make
# ... optionally pass make the cmd line args, as in './build.py clean' runs 'make clean'
rootdir = zest.ZestRoot()

builddirs = []
buildargs = {}
builddirs.append( 'polarssl-1.2.3' )
builddirs.append( 'zest/src' )
builddirs.append( 'lime/src' )
builddirs.append( 'iaperf/src' )
builddirs.append( 'likwid-3.0' )

if len( sys.argv ) > 1:
    cmd = ' '.join( ['make'] + sys.argv[ 1: ] )
else:
    cmd = 'make'

# populate the build args
for builddir in builddirs:
    buildargs[ builddir ] = ''

if cmd.count( 'clean' ) == 0:
    buildargs[ 'polarssl-1.2.3' ] = 'lib'

for builddir in builddirs:
    srcdir = os.path.join( rootdir, builddir )
    os.chdir( srcdir )
    ucmd = ' '.join([ cmd, buildargs[ builddir ] ] )
    zest.SystemWrapper( ucmd )


